<%= error_messages_for :media %>
<%= error_messages_for :image_file %>
<%= error_messages_for :video_file %>

<script type="text/javascript" src="/javascripts/swfupload/swfupload.js"></script>
<script type="text/javascript" src="/javascripts/swfupload/swfupload.graceful_degradation.js"></script>
<script type="text/javascript" src="/javascripts/swfupload/fileprogress.js"></script>
<script type="text/javascript" src="/javascripts/swfupload/handlers.js"></script>

<script type="text/javascript">
		var swfu;

		Event.observe(window, 'load', function () {

			swfu = new SWFUpload({
				// Backend settings
				upload_url: "/media/create?_tecnophoto_session=<%= session.session_id %>",
				// upload_url: "/media/create",	// Relative to the SWF file, you can use an absolute URL as well.
				// file_post_name: "data[uploaded_data]",

				// Flash file settings
				file_size_limit : "51200",	// 50 MB
				file_types : "*.wmv;*.avi;*.mp4;*.mpeg;*.mpg;*.flv;*.png;*.gif;*.jpeg;*.jpg",	// or you could use something like: "*.doc;*.wpd;*.pdf",
				file_types_description : "Media Files",
				file_upload_limit : "0", // Even though I only want one file I want the user to be able to try again if an upload fails
				file_queue_limit : "1", // this isn't needed because the upload_limit will automatically place a queue limit

				// Event handler settings
				swfupload_loaded_handler : swfUploadLoaded,
				
				//file_dialog_start_handler : fileDialogStart,		// I don't need to override this handler
				file_queued_handler : fileQueued,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				
				//upload_start_handler : uploadStart,	// I could do some client/JavaScript validation here, but I don't need to.
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : uploadComplete,

				// Flash Settings
				flash_url : "/flash/swfupload.swf",	// Relative to this file

				// UI settings
				swfupload_element_id : "flashUI",		// setting for the graceful degradation plugin
				degraded_element_id : "degradedUI",

				custom_settings : {
					progress_target : "fsUploadProgress",
					upload_successful : false
				},
				
				// Debug settings
				debug: false
			});

		});
	</script>




<% form_for(:media, :url => {:action => 'create'}, 
                      :html => { :multipart => true }) do |f| -%>
  <p>
    <label for="title">Title:</label>
    <%= text_field 'media', 'title', :size => 50 %>
  </p>
  <p>
    <label for="category_id">Category:</label>
    <%= select("media", "category_id", Category.find(:all).collect {|p| [ p.name, p.id ] }, {:include_blank => 'None'}, {:style => 'width: 300px;'}) %>
  </p>
  <p>
    <label for="uploaded_data">Image:</label>
  <% # fields_for "data" do |g| %>
         <% # = g.file_field :uploaded_data, {'accept' => 'media/gif'} %>

        <% # end %>

<div id="flashUI" style="display: none;">
						<!-- The UI only gets displayed if SWFUpload loads properly -->
						<div>

							<input type="text" id="txtFileName" disabled="true" style="border: solid 1px; background-color: #FFFFFF;" />
							<input id="btnBrowse" type="button" value="Browse..." onclick="fileBrowse.apply(swfu)" />
							(50 MB max) </div>
						<div class="flash" id="fsUploadProgress">
							<!-- This is where the file progress gets shown.  SWFUpload doesn't update the UI directly.
										The Handlers (in handlers.js) process the upload events and make the UI updates -->
						</div>
						<input type="hidden" name="hidFileID" id="hidFileID" value="" />
						<!-- This is where the file ID is stored after SWFUpload uploads the file and gets the ID back from upload.php -->

					</div>
					<div id="degradedUI">
						<!-- This is the standard UI.  This UI is shown by default but when SWFUpload loads it will be
								hidden and the "flashUI" will be shown -->
						<input type="file" name="data[uploaded_data]" id="resume_degraded" />
						(50 MB max)<br/>
					</div>

  </p>
  <p>
    <label for="description">Description:</label><br>
    <%= text_area 'media', 'description', :style => 'width: 580px; padding: 5px', :id => 'new_media_textarea', :onKeyUp => 'updatePreview(\'media\',\'new_media\');' -%>
  </p>
  <p>
    <label for="tag_list">Tags:</label> <%= text_field 'media', 'tag_list', :size => 50 %>
  </p>
  <p>
      <%= submit_tag "Add Media", :onClick => "hs.htmlExpand(this, { contentId: 'pleaseWait', align: 'center' } )", :id=>"btnSubmit" %>
  </p>
<% end -%>

<h2>Preview</h2><img src="/images/spinner.gif" style="display: none; border: 0;" id="new_media_preview_spinner" /><div id="new_media_preview"></div>
<div id="pleaseWait" style="text-align: center; width: 400px; height: 150px;font-weight: bold; font-size: 20px; padding-top: 50px;" class="highslide-html-content">Please Wait<br /><br /><img src="/images/big-spinner.gif" /></div>
